$(document).ready(function() {
	$("#pageSelection").bind("change",function(){
		$("#departmentTable").load(getRootPath()+ "/MainMenu/configuration/departmentList.htm",{pageIndex:$("#pageSelection").val()});
	});
	
	$("#previousButton").bind("click",function(){
		$("#departmentTable").load(getRootPath()+ "/MainMenu/configuration/departmentList.htm",{pageIndex:$("#previousPageIndex").val()});
	});
	
	$("#nextButton").bind("click",function(){
		$("#departmentTable").load(getRootPath()+ "/MainMenu/configuration/departmentList.htm",{pageIndex:$("#nextPageIndex").val()});
	});
	
	$( "#progressbar" ).dialog({
		autoOpen:false,
		width:100,
		height:50,
		modal:true
	});
});

function edit(id) {
	$.getJSON(getRootPath()+ "/MainMenu/configuration/editDepartment.htm",{departmentID:id}, function(json){
		  $("#departmentName").val(json.department.departmentName);
		  $("#description").val(json.department.description);
		  $("#departmentID").val(json.department.id);
		  //data load complete, open the dialog
		  $("#addDepartmentForm").dialog("open");
		});
}

function deleteDepartment(id){
	$( "#progressbar" ).dialog("open");
	$.getJSON(getRootPath()+ "/MainMenu/configuration/deleteDepartment.htm",{departmentID:id}, function(json){
		if(json.error==undefined){
			$( "#progressbar" ).dialog("close");
			alert("删除成功");
			$("#departmentTable").load(getRootPath()+ "/MainMenu/configuration/departmentList.htm",{pageIndex:$("#currentPageIndex").val()});
		}else{
			alert("删除失败");
		}
	});
}